﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Text;
using Maticsoft.Common;
using LTP.Accounts.Bus;
namespace dzs.Web.user
{
    public partial class Modify : Page
    {       

        		protected void Page_Load(object sender, EventArgs e)
		{
			if (!Page.IsPostBack)
			{
				if (Request.Params["id"] != null && Request.Params["id"].Trim() != "")
				{
					int user_id=(Convert.ToInt32(Request.Params["id"]));
					ShowInfo(user_id);
				}
			}
		}
			
	private void ShowInfo(int user_id)
	{
		dzs.BLL.user bll=new dzs.BLL.user();
		dzs.Model.user model=bll.GetModel(user_id);
		this.lbluser_id.Text=model.user_id.ToString();
		this.txtuser_name.Text=model.user_name;
		this.txtuser_login.Text=model.user_login;
		this.txtuser_pass.Text=model.user_pass;
		this.txtuser_mobelPhone.Text=model.user_mobelPhone;
		this.txtuser_phone.Text=model.user_phone;
		this.txtuser_fax.Text=model.user_fax;
		this.txtuser_company.Text=model.user_company;
		this.txtuser_email.Text=model.user_email;
		this.txtroles_id.Text=model.roles_id.ToString();
		this.txtremark.Text=model.remark;
		this.txtsid.Text=model.sid.ToString();

	}

		public void btnSave_Click(object sender, EventArgs e)
		{
			
			string strErr="";
			if(this.txtuser_name.Text.Trim().Length==0)
			{
				strErr+="user_name不能为空！\\n";	
			}
			if(this.txtuser_login.Text.Trim().Length==0)
			{
				strErr+="user_login不能为空！\\n";	
			}
			if(this.txtuser_pass.Text.Trim().Length==0)
			{
				strErr+="user_pass不能为空！\\n";	
			}
			if(this.txtuser_mobelPhone.Text.Trim().Length==0)
			{
				strErr+="user_mobelPhone不能为空！\\n";	
			}
			if(this.txtuser_phone.Text.Trim().Length==0)
			{
				strErr+="user_phone不能为空！\\n";	
			}
			if(this.txtuser_fax.Text.Trim().Length==0)
			{
				strErr+="user_fax不能为空！\\n";	
			}
			if(this.txtuser_company.Text.Trim().Length==0)
			{
				strErr+="user_company不能为空！\\n";	
			}
			if(this.txtuser_email.Text.Trim().Length==0)
			{
				strErr+="user_email不能为空！\\n";	
			}
			if(!PageValidate.IsNumber(txtroles_id.Text))
			{
				strErr+="所属角色格式错误！\\n";	
			}
			if(this.txtremark.Text.Trim().Length==0)
			{
				strErr+="remark不能为空！\\n";	
			}
			if(!PageValidate.IsNumber(txtsid.Text))
			{
				strErr+="物料员所管仓库格式错误！\\n";	
			}

			if(strErr!="")
			{
				MessageBox.Show(this,strErr);
				return;
			}
			int user_id=int.Parse(this.lbluser_id.Text);
			string user_name=this.txtuser_name.Text;
			string user_login=this.txtuser_login.Text;
			string user_pass=this.txtuser_pass.Text;
			string user_mobelPhone=this.txtuser_mobelPhone.Text;
			string user_phone=this.txtuser_phone.Text;
			string user_fax=this.txtuser_fax.Text;
			string user_company=this.txtuser_company.Text;
			string user_email=this.txtuser_email.Text;
			int roles_id=int.Parse(this.txtroles_id.Text);
			string remark=this.txtremark.Text;
			int sid=int.Parse(this.txtsid.Text);


			dzs.Model.user model=new dzs.Model.user();
			model.user_id=user_id;
			model.user_name=user_name;
			model.user_login=user_login;
			model.user_pass=user_pass;
			model.user_mobelPhone=user_mobelPhone;
			model.user_phone=user_phone;
			model.user_fax=user_fax;
			model.user_company=user_company;
			model.user_email=user_email;
			model.roles_id=roles_id;
			model.remark=remark;
			model.sid=sid;

			dzs.BLL.user bll=new dzs.BLL.user();
			bll.Update(model);
			Maticsoft.Common.MessageBox.ShowAndRedirect(this,"保存成功！","List.aspx");

		}


        public void btnCancle_Click(object sender, EventArgs e)
        {
            Response.Redirect("list.aspx");
        }
    }
}
